package com.show.util;

/**
 * 评价工具类
 *
 * @author liukai
 */
public class ScoreUtil {


    /**
     * 求率
     *
     * @param a 分子
     * @param b 分母
     * @author liukai
     */
    public static int getRatio(int a, int b) {
        if (b == 0) {
            return 0;
        } else {
            double ratio = (double) a / b;
            return (int) (ratio * 100);
        }
    }


    /**
     * 算评价等级
     *
     * @param overallScore 综合评价
     * @return 等级
     * @author liukai
     */
    public static char getLevel(int overallScore) {
        if (overallScore >= 90 && overallScore <= 100) {
            return 'A';
        }

        if (overallScore >= 75 && overallScore < 90) {
            return 'B';
        }

        if (overallScore >= 60 && overallScore < 75) {
            return 'C';
        }

        if (overallScore >= 40 && overallScore < 60) {
            return 'D';
        }

        if (overallScore >= 0 && overallScore < 40) {
            return 'E';
        }
        return 0;
    }

    /**
     * 获得综合得分
     *
     * @author liukai
     */
    public static int getOverallScore(int... params) {
        double divisor = (1.0 / params.length);
        int score = 0;
        for (int num : params) {
            score = score + (int) (num * divisor);

        }
        return score;
    }

}
